package com.itheima.controller;

import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class AccountController {
    @Autowired
    private AccountService accountService;

    @RequestMapping("findAll")
    /*@ResponseBody*/
    public ModelAndView findAll(ModelAndView modelAndView) {
        List<Account> all = accountService.findAll();
        modelAndView.addObject("accounts",all);
        System.out.println(all);
        modelAndView.setViewName("/WEB-INF/pages/page.jsp");
        return modelAndView;
    }

    @RequestMapping("findAll02")
    @ResponseBody
    public List<Account> findAll02() {
        List<Account> all = accountService.findAll();
        return all;
    }

}
